/*
 * Created by SharpDevelop.
 * User: c0148643
 * Date: 11/05/2010
 * Time: 13:04
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Data;
using System.Data.SQLite;
using System.Collections.Generic;

namespace pontoIndividual
{
	/// <summary>
	/// Description of tipoPonto.
	/// </summary>
	public class tipoPonto
	{
		private int idtipoPonto;
		public int IdtipoPonto {
			get { return idtipoPonto; }
			set { idtipoPonto = value; }
		}
		private string dscPonto;
		public string DscPonto {
			get { return dscPonto; }
			set { dscPonto = value; }
		}
		
		public tipoPonto()
		{
			
		}
		
		public tipoPonto(int pIdTipoPonto, string pDscTipoPonto) {
			idtipoPonto = pIdTipoPonto;
			dscPonto = pDscTipoPonto;
		}
		
		
		public void loadTipoFromDb(int tipo) {
			
			using (conexao c = new conexao() ) {
				c.open();
				
				SQLiteCommand cm = new SQLiteCommand("SELECT idtipoponto, dscponto FROM tipoPonto WHERE idtipoponto = " + tipo, c.conn);
				SQLiteDataReader dr = cm.ExecuteReader();
				
				while(dr.Read()) {
					idtipoPonto = int.Parse(dr[0].ToString());
					dscPonto = dr[1].ToString();
				}
				
				dr.Close();
				dr.Dispose();
			}
			
			
		}
		
		public List<tipoPonto> listAll() {
			List<tipoPonto> t = new List<tipoPonto>();
			
			using (conexao c = new conexao() ) {
				c.open();
				
				SQLiteCommand cm = new SQLiteCommand("SELECT idtipoponto, dscponto FROM tipoPonto", c.conn);
				SQLiteDataReader dr = cm.ExecuteReader();
				
				while(dr.Read()) {
					t.Add(new tipoPonto(int.Parse(dr[0].ToString()), dr[1].ToString()));
				}
				
				dr.Close();
				dr.Dispose();
			}
			
			return t;
		}
	}
}
